// 匹配器

/* 
  类型 匹配器
*/
// toBe() => === 绝对匹配
test("toBe", () => {
  expect("test").toBe("test");
  const obj = { name: "Alomy" };
  expect(obj).toBe(obj); // 通过
  // expect(obj).toBe({ name: "Alomy" }); // 引用不同, 故未通过
});

// toEqual() => 内容、结果匹配
test("toEqual", () => {
  const obj = { name: "Alomy" };
  expect(obj).toEqual({ name: "Alomy" }); // 通过
});

// toBeNull() => 匹配 null
test("toBeNull", () => {
  const value = null;
  expect(value).toBeNull();
});

// toBeUndefined() => 匹配 undefined
test("toBeUndefined", () => {
  const value = undefined;
  expect(value).toBeUndefined();
});

// toBeDefined() => 匹配 非 undefined
test("toBeDefined", () => {
  const value = "Alomy";
  expect(value).toBeDefined();
});

// toBeTruthy() => 匹配 正
test("toBeTruthy", () => {
  const value = 1;
  expect(value).toBeTruthy();
});

// toBeFalsy() => 匹配 假
test("toBeFalsy", () => {
  const value = 0;
  expect(value).toBeFalsy();
});

/* 
  数字 匹配器
*/
// toBeGreater() => 匹配 大于 >
test("toBeGreaterThan", () => {
  const num = 10;
  expect(num).toBeGreaterThan(9);
});

// toBeLessThan() => 匹配 小于 <
test("toBeLessThan", () => {
  const num = 10;
  expect(num).toBeLessThan(11);
});

// toBeGreaterThanOrEqual() => 匹配 大于等于 >=
test("toBeGreaterThanOrEqual", () => {
  const num = 10;
  expect(num).toBeGreaterThanOrEqual(10);
});

// toBeLessThanOrEqual() => 匹配 小于等于 <=
test("toBeLessThanEqual", () => {
  const num = 10;
  expect(num).toBeLessThanOrEqual(10);
});

// toBeCloseTo() => 匹配 浮点数的近似相等性
test("toBeCloseTo", () => {
  const num1 = 0.1;
  const num2 = 0.2;
  expect(num1 + num2).toBeCloseTo(0.3);
});

/* 
  字符串
*/
// toMatch() => 匹配 字符串/正则
test("toMatch", () => {
  const str = "Alomy, Dell, Kobe";
  expect(str).toMatch("Alomy");
});

// toContain() => 匹配数组/Set
test("toContain", () => {
  const array = ["Alomy", "Dell", "Kobe", "Alomy"];
  const set = new Set(array);
  expect(array).toContain("Alomy");
  expect(set).toContain("Alomy");
});

const throwNewErrorFunc = () => {
  throw new Error("this is error");
};
// toThrow() => 匹配 错误
test("toThrow", () => {
  expect(throwNewErrorFunc).toThrow("this is error");
});

// not => 非
test("not", () => {
  expect(throwNewErrorFunc).not.toThrow("this is not error");
});
